/**
 * Created by dell on 2017/7/5.
 */
import {Component, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';
import {Observable, Subject} from 'rxjs';
import {ActivatedRoute} from '@angular/router';
import {ShareService} from "@share/share.service";
import {ImageServeService} from "@shared/service/image/image-serve.service";
import {ToolsService} from "@shared/service/tools/tools.service";

@Component({
  selector: 'create-success',
  templateUrl: './group-center.component.html',
  styleUrls: ['./group-center.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class CreateSuccessComponent implements OnInit, OnDestroy {
  public groupitem: any;
  public memerlist: any;
  public groupId: any;
  public defaulticon: string = this.imgSer.getUserIcon();
  public ngUnsubscribe: Subject<void> = new Subject<void>();

  constructor(
    private shareSer: ShareService,
    private imgSer: ImageServeService,
    private router: ActivatedRoute,
    public ToolServices: ToolsService
  ) {
  }

  getgroupinfo() {
    this.shareSer.getGroupInfo(this.groupId).subscribe(res => {
      if (res && res.result === '0') {
        this.groupitem = res.data;
      }
    });
  }

  getgroupmember() {
    this.shareSer.getGroupMemberList(this.groupId).subscribe(res => {
      if (res.result === '0') {
        this.memerlist = res.data.list;
      }
    });
  }

  godownload() {
    this.ToolServices.presentConfirm('下载求苗APP，看更多精彩内容！');
  }

  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }

  ngOnInit() {
    this.router.params
      .subscribe((param) => {
        if (param['groupId']) {
          this.groupId = param['groupId'];
          this.getgroupinfo();
          this.getgroupmember();
        }
      });
  }
}
